<?php

use think\facade\Route;

// CRM模块路由
Route::group('api/crm', function () {
    // 客户管理相关路由
    Route::group('customer', function () {
        Route::get('/list', 'crm.Customer/list');                // 查看客户列表
        Route::get('/detail/:id', 'crm.Customer/detail');        // 获取客户详情
        Route::get('/detail', 'crm.Customer/detail');            // 获取客户详情（兼容格式）
        Route::post('/create', 'crm.Customer/create');           // 新增客户
        Route::post('/add', 'crm.Customer/add');                 // 新增客户（需审核）
        Route::put('/update', 'crm.Customer/update');            // 更新客户
        Route::put('/edit', 'crm.Customer/update');              // 编辑客户（需审核）
        Route::delete('/delete/:id', 'crm.Customer/delete');     // 删除客户
        Route::delete('/del', 'crm.Customer/del');               // 删除客户（兼容格式）
        Route::put('/toPublic/:id', 'crm.Customer/toPublic');    // 转移客户到公海
        Route::put('/markCooperation', 'crm.Customer/markCooperation'); // 标记为已合作
        Route::put('/moveToPublic', 'crm.Customer/moveToPublic'); // 移入公海
        Route::post('/claimFromPublic', 'crm.Customer/claimFromPublic'); // 从公海领取
        Route::get('/options', 'crm.Customer/options');          // 获取客户选项（用于下拉选择）
        Route::get('/industryOptions', 'crm.Customer/industryOptions'); // 获取行业选项
        Route::get('/scaleOptions', 'crm.Customer/scaleOptions'); // 获取企业规模选项
        Route::get('/sourceOptions', 'crm.Customer/sourceOptions'); // 获取客户来源选项
        Route::get('/userOptions', 'crm.Customer/userOptions'); // 获取负责人选项
        Route::get('/departmentOptions', 'crm.Customer/departmentOptions'); // 获取部门选项

        // 客户审核相关
        Route::get('/reviewList', 'crm.Customer/reviewList');    // 审核列表
        Route::post('/reviewApprove', 'crm.Customer/reviewApprove'); // 审核处理
        Route::get('/myReviews', 'crm.Customer/myReviews');      // 当前用户审核记录
        Route::post('/cancelReview', 'crm.Customer/cancelReview'); // 撤销审核申请
    });
    
    // 联系人管理相关路由
    Route::group('contact', function () {
        Route::get('/list', 'crm.Contact/list');              // 查看联系人列表
        Route::post('/add', 'crm.Contact/add');               // 新增联系人
        Route::put('/edit', 'crm.Contact/edit');              // 编辑联系人（需审核）
        Route::delete('/del', 'crm.Contact/del');             // 删除联系人（需审核）
        Route::post('/setPrimary', 'crm.Contact/setPrimary'); // 设置主要联系人
        Route::get('/detail', 'crm.Contact/detail');          // 获取联系人详情
        
        // 联系人审核相关
        Route::get('/reviewList', 'crm.Contact/reviewList');  // 审核列表
        Route::post('/reviewApprove', 'crm.Contact/reviewApprove'); // 审核处理
    });

    // 销售机会管理相关路由
    Route::group('opportunity', function () {
        Route::get('/list', 'crm.Opportunity/list');             // 查看销售机会列表
        Route::get('/detail/:id', 'crm.Opportunity/detail');     // 获取销售机会详情
        Route::get('/detail', 'crm.Opportunity/detail');         // 获取销售机会详情（兼容格式）
        Route::post('/add', 'crm.Opportunity/add');              // 新建销售机会
        Route::post('/create', 'crm.Opportunity/add');           // 新建销售机会（RESTful风格）
        Route::put('/edit', 'crm.Opportunity/edit');             // 编辑销售机会
        Route::put('/update', 'crm.Opportunity/edit');           // 编辑销售机会（RESTful风格）
        Route::delete('/del', 'crm.Opportunity/del');            // 删除销售机会
        Route::delete('/delete/:id', 'crm.Opportunity/del');     // 删除销售机会（RESTful风格）
        Route::post('/convert', 'crm.Opportunity/convert');      // 转化销售机会为订单
        Route::post('/markLose', 'crm.Opportunity/markLose');    // 标记销售机会失效
        Route::get('/statistics', 'crm.Opportunity/statistics'); // 获取销售机会统计
        Route::get('/stageOptions', 'crm.Opportunity/stageOptions'); // 获取销售阶段选项
        Route::get('/levelOptions', 'crm.Opportunity/levelOptions'); // 获取销售机会等级选项
        Route::get('/categoryOptions', 'crm.Opportunity/categoryOptions'); // 获取销售机会类别选项
        Route::get('/statusOptions', 'crm.Opportunity/statusOptions'); // 获取销售机会状态选项
        Route::post('/batch', 'crm.Opportunity/batch');          // 批量操作销售机会
        Route::get('/trace', 'crm.Opportunity/getTrace');        // 获取销售机会跟进记录
        Route::post('/addTrace', 'crm.Opportunity/addTrace');    // 添加销售机会跟进记录
    });

    // 客户跟进记录相关路由
    Route::group('followup', function () {
        Route::get('/list', 'crm.Followup/list');             // 查看跟进记录列表
        Route::post('/add', 'crm.Followup/add');              // 新建跟进记录
        Route::post('/create', 'crm.Followup/add');           // 新建跟进记录（RESTful风格）
        Route::put('/edit', 'crm.Followup/edit');             // 编辑跟进记录
        Route::put('/update', 'crm.Followup/edit');           // 编辑跟进记录（RESTful风格）
        Route::delete('/del', 'crm.Followup/del');            // 删除跟进记录
        Route::delete('/delete/:id', 'crm.Followup/del');     // 删除跟进记录（RESTful风格）
        Route::get('/detail/:id', 'crm.Followup/detail');     // 获取跟进记录详情
        Route::get('/options', 'crm.Followup/options');       // 获取所有选项（类型+结果）
        Route::get('/typeOptions', 'crm.Followup/typeOptions'); // 获取跟进类型选项
        Route::get('/resultOptions', 'crm.Followup/resultOptions'); // 获取跟进结果选项
    });
    
    // 业务订单相关路由
    Route::group('order', function () {
        Route::get('/list', 'crm.Order/list');                // 查看订单列表
        Route::get('/detail/:id', 'crm.Order/detail');        // 获取订单详情
        Route::post('/add', 'crm.Order/add');                 // 新建业务订单
        Route::put('/edit', 'crm.Order/edit');               // 编辑业务订单
        Route::delete('/delete/:id', 'crm.Order/del');       // 删除业务订单
        Route::post('/review', 'crm.Order/review');          // 审核业务订单
        Route::post('/addPayment', 'crm.Order/addPayment');  // 添加付款记录
        Route::get('/options', 'crm.Order/options');         // 获取所有订单选项
        Route::get('/typeOptions', 'crm.Order/typeOptions');  // 获取订单类型选项
        Route::get('/statusOptions', 'crm.Order/statusOptions'); // 获取订单状态选项
        Route::get('/paymentMethodOptions', 'crm.Order/paymentMethodOptions'); // 获取付款方式选项
        Route::get('/paymentStatusOptions', 'crm.Order/paymentStatusOptions'); // 获取付款状态选项
        Route::get('/contractStatusOptions', 'crm.Order/contractStatusOptions'); // 获取合同状态选项
        Route::get('/type/list', 'crm.Order/getOrderTypeList');         // 获取订单类型列表
        Route::get('/type/category/:category', 'crm.Order/getOrderTypesByCategory'); // 根据订单大类获取类型
    });
    
    // 付款记录相关路由
    Route::group('payment', function () {
        Route::get('/list', 'crm.Payment/list');              // 查看付款记录列表
        Route::post('/add', 'crm.Payment/add');              // 新建付款记录
        Route::put('/edit', 'crm.Payment/edit');             // 编辑付款记录
        Route::delete('/del', 'crm.Payment/del');            // 删除付款记录
    });
    
    // 诉讼订单相关路由
    Route::group('lawsuit-order', function () {
        Route::get('/list', 'crm.LawsuitLegalOrder/lawsuitList');           // 获取诉讼订单列表
        Route::get('/detail/:id', 'crm.LawsuitLegalOrder/lawsuitDetail');   // 获取诉讼订单详情
        Route::post('/create', 'crm.LawsuitLegalOrder/lawsuitCreate');      // 创建诉讼订单
        Route::put('/update', 'crm.LawsuitLegalOrder/lawsuitUpdate');       // 更新诉讼订单
        Route::delete('/delete/:id', 'crm.LawsuitLegalOrder/lawsuitDelete'); // 删除诉讼订单
    });
    
    // 法务订单相关路由
    Route::group('legal-service-order', function () {
        Route::get('/list', 'crm.LawsuitLegalOrder/legalList');               // 获取法务订单列表
        Route::get('/detail/:id', 'crm.LawsuitLegalOrder/legalDetail');       // 获取法务订单详情
        Route::post('/create', 'crm.LawsuitLegalOrder/legalCreate');          // 创建法务订单
        Route::put('/update', 'crm.LawsuitLegalOrder/legalUpdate');           // 更新法务订单
        Route::delete('/delete/:id', 'crm.LawsuitLegalOrder/legalDelete');    // 删除法务订单
    });
    
    // 审核记录相关路由
    Route::group('audit', function () {
        Route::get('/list', 'crm.Audit/list');                // 查看审核记录列表
        Route::get('/pending', 'crm.Audit/pending');          // 查看待审核记录
        Route::post('/process', 'crm.Audit/process');        // 处理审核
    });
    
    // 客户联系人审核相关路由
    Route::group('contactAudit', function () {
        Route::get('/list', 'crm.ContactAudit/list');         // 查看联系人审核记录
        Route::post('/submit', 'crm.ContactAudit/submit');    // 提交联系人修改审核
        Route::post('/process', 'crm.ContactAudit/process');  // 处理联系人审核
    });
    
    // 客户分类管理
    Route::group('customerCategory', function () {
        Route::get('/list', 'crm.CustomerCategory/list');    // 查看客户分类列表
        Route::post('/add', 'crm.CustomerCategory/add');     // 添加客户到分类
        Route::delete('/remove', 'crm.CustomerCategory/remove'); // 从分类移除客户
        Route::get('/cooperated', 'crm.CustomerCategory/cooperated'); // 获取已合作客户列表
        Route::get('/publicPool', 'crm.CustomerCategory/publicPool'); // 获取公海客户列表
    });
    
    // 统计报表
    Route::group('statistics', function () {
        Route::get('/overview', 'crm.Stats/overview');   // 获取CRM概览统计
        Route::get('/followupTrend', 'crm.Stats/followupTrend'); // 跟进趋势统计
        Route::get('/orderAnalysis', 'crm.Stats/orderAnalysis'); // 订单分析统计
        Route::get('/todos', 'crm.Stats/getTodos');     // 获取待办事项
        Route::get('/recentFollowups', 'crm.Stats/getRecentFollowups'); // 获取最近跟进记录
    });
    
    // 审核管理 - 客户审核
    Route::group('customerReview', function () {
        Route::get('/list', 'crm.CustomerReview/list');         // 获取客户审核列表
        Route::get('/detail', 'crm.CustomerReview/detail');     // 获取审核详情
        Route::post('/approve', 'crm.CustomerReview/approve'); // 审核处理（通过/驳回）
        Route::get('/statistics', 'crm.CustomerReview/statistics'); // 获取审核统计
    });
    
    // 审核管理 - 订单审核
    Route::group('orderReview', function () {
        Route::get('/list', 'crm.OrderReview/list');               // 获取订单审核列表
        Route::get('/detail', 'crm.OrderReview/detail');           // 获取审核详情
        Route::post('/submit', 'crm.OrderReview/submit');          // 提交审核申请
        Route::post('/approve', 'crm.OrderReview/approve');       // 审核处理（通过/驳回）
        Route::get('/statistics', 'crm.OrderReview/statistics');   // 获取审核统计
        Route::get('/businessTypeOptions', 'crm.OrderReview/businessTypeOptions'); // 获取业务类型选项
        Route::get('/reviewTypeOptions', 'crm.OrderReview/reviewTypeOptions'); // 获取审核类型选项
    });
});